home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / makefont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-05  |  3.1 KB  |  136 lines

  1. /*
  2.  *   This software is Copyright 1988 by Radical Eye Software.
  3.  *   All Rights Reserved.
  4.  */
  5. #include <stdio.h>
  6. #ifdef SYSV
  7. #include <string.h>
  8. #else
  9. #include <strings.h>
  10. #endif
  11. #include "structures.h"
  12. extern int quiet ;
  13. extern int filter ;
  14. extern char *mfmode ;
  15. /*
  16.  *   Calculate magstep values.
  17.  */
  18. static int
  19. magstep(n, bdpi)
  20. register int n, bdpi ;
  21. {
  22.    register float t ;
  23.    int neg = 0 ;
  24.  
  25.    if (n < 0) {
  26.       neg = 1 ;
  27.       n = -n ;
  28.    }
  29.    if (n & 1) {
  30.       n &= ~1 ;
  31.       t = 1.095445115 ;
  32.    } else
  33.       t = 1.0 ;
  34.    while (n > 8) {
  35.       n -= 8 ;
  36.       t = t * 2.0736 ;
  37.    }
  38.    while (n > 0) {
  39.       n -= 2 ;
  40.       t = t * 1.2 ;
  41.    }
  42.    if (neg)
  43.       return((int)(0.5 + bdpi / t)) ;
  44.    else
  45.       return((int)(0.5 + bdpi * t)) ;
  46. }
  47. char *command = "MakeTeXPK %n %d %b %m" ;
  48. /*
  49.  *   This routine tries to create a font by executing a command, and
  50.  *   then opening the font again if possible.
  51.  */
  52. static char buf[125] ;
  53. void
  54. makefont(name, dpi, bdpi)
  55.    char *name ;
  56.    int dpi, bdpi ;
  57. {
  58.    register char *p, *q ;
  59.    register int m, n ;
  60.  
  61.    for (p=command, q=buf; *p; p++)
  62.       if (*p != '%')
  63.          *q++ = *p ;
  64.       else {
  65.          switch (*++p) {
  66. case 'n' : case 'N' :
  67.             (void)strcpy(q, name) ;
  68.             break ;
  69. case 'd' : case 'D' :
  70.             (void)sprintf(q, "%d", dpi) ;
  71.             break ;
  72. case 'b' : case 'B' :
  73.             (void)sprintf(q, "%d", bdpi) ;
  74.             break ;
  75. case 'm' : case 'M' :
  76. /*
  77.  *   Here we want to return a string.  If we can find some integer
  78.  *   m such that floor(0.5 + bdpi * 1.2 ^ (m/2)) = dpi, we write out
  79.  *      magstep(m/2)
  80.  *   where m/2 is a decimal number; else we write out
  81.  *      dpi/bdpi
  82.  *   We do this for the very slight improvement in accuracy that
  83.  *   magstep() gives us over the rounded dpi/bdpi.
  84.  */
  85.             m = 0 ;
  86.             if (dpi < bdpi) {
  87.                while (1) {
  88.                   m-- ;
  89.                   n = magstep(m, bdpi) ;
  90.                   if (n == dpi)
  91.                      break ;
  92.                   if (n < dpi || m < -40) {
  93.                      m = 9999 ;
  94.                      break ;
  95.                   }
  96.                }
  97.             } else if (dpi > bdpi) {
  98.                while (1) {
  99.                   m++ ;
  100.                   n = magstep(m, bdpi) ;
  101.                   if (n == dpi)
  102.                      break ;
  103.                   if (n > dpi || m > 40) {
  104.                      m = 9999 ;
  105.                      break ;
  106.                   }
  107.                }
  108.             }
  109.             if (m == 9999) {
  110.                (void)sprintf(q, "%d+%d/%d", dpi/bdpi, dpi%bdpi, bdpi) ;
  111.             } else if (m >= 0) {
  112.                (void)sprintf(q, "magstep\\(%d.%d\\)", m/2, (m&1)*5) ;
  113.             } else {
  114.                (void)sprintf(q, "magstep\\(-%d.%d\\)", (-m)/2, (m&1)*5) ;
  115.             }
  116.             break ;
  117. case 0 :    *q = 0 ;
  118.             break ;
  119. default:    *q++ = *p ;
  120.             *q = 0 ;
  121.             break ;
  122.          }
  123.          q += strlen(q) ;
  124.       }
  125.    *q = 0 ;
  126.    if (mfmode) {
  127.       strcpy(q, " ") ;
  128.       strcat(q, mfmode) ;
  129.    }
  130.    if (filter)
  131.       (void)strcat(buf, " >/dev/null") ;
  132.    if (! quiet)
  133.       (void)fprintf(stderr, "- %s\n", buf) ;
  134.    (void)system(buf) ;
  135. }
  136.